package com.audaque.springboot.foshanupload.amqp.config;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(name = "spring.rabbitmq.listener.simple.retry.enabled", havingValue = "true")
@Configuration
public class RepublishOverConfig {

    @Bean
    public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
        //RepublishMessageRecoverer：重试耗尽后，将失败消息投递到指定的交换机，如死信队列，后续由人工集中处理。
        return new RepublishMessageRecoverer(rabbitTemplate, "deadExchange", "republishOver");
    }

}
